<template>
	<view>
		<uni-indexed-list :options="list" :show-select="true" />
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	const list = ref([{
		"letter": "A",
		"data": [
			"阿克苏机场",
			"阿拉山口机场",
			"阿勒泰机场",
			"阿里昆莎机场",
			"安庆天柱山机场",
			"澳门国际机场"
		]
	}])

	// function getCity() {
	// 	return new Promise((resolve, reject) => {
	// 			uniCloud.database().collection('opendb-city-china').where({
	// 				type: 1
	// 			}).limit(500).get().then(resp => {
	// 				resolve(resp)
	// 			})
	// 		}
	// 	}
	
	function getCity() {
		return new Promise((resolve, reject) => {
			uniCloud.database().collection('opendb-city-china').where({
				type: 1
			}).limit(500).get().then(resp => {
				resolve(resp)
			})
		})
	}

	getCity().then(resp => {
		const arr = []
		resp.result.data.forEach(v => {

			const result = arr.find(item => item.letter === v.first_letter)
			if (result) {
				result.data.push(v.name)
			} else {
				arr.push({
					letter: v.first_letter,
					data: [v.name]
				})
			}
		})
		arr.sort((a, b) => a.letter.charCodeAt() - b.letter.charCodeAt())
		list.value = arr
	})
</script>

<style lang="scss">

</style>